#pragma once

#include "gl/glew.h"

#include "../Core/Vector.h"

#include "Uniform.h"
#include "ICleanableObserver.h"

using namespace Core;

namespace Renderer
{
	namespace GL3x
	{
		class UniformFloatVector4GL3x : public TemplateUniform<Vector4F>, public ICleanable
		{
		public:
			UniformFloatVector4GL3x(std::string name, int location, ICleanableObserver* observer)
				:TemplateUniform<Vector4F>(name, UniformType::FloatVector4), _observer(observer)
			{
				_location = location;
				_dirty = true;
				_observer->NotifyDirty(this);
			}

			Vector4F GetValue() override
			{
				return _value;
			}

			void SetValue(const Vector4F& value) override
			{
				if (!_dirty && (_value != value))
				{
					_dirty = true;
					_observer->NotifyDirty(this);
				}
				_value = value;
			}

			void Clean()
			{
				glUniform4f(_location, _value.x, _value.y, _value.z, _value.w);
				_dirty = false;
			}


		private:
			int _location;
			Vector4F _value;
			bool _dirty;
			ICleanableObserver* _observer;
		};
	}
}